/****

    activequant - activestocks.eu

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License along
    with this program; if not, write to the Free Software Foundation, Inc.,
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

	
	contact  : contact@activestocks.eu
    homepage : http://www.activestocks.eu

****/
package org.activequant.core.domainmodel.account;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.activequant.util.tools.ArrayUtils;


/**
 * 
 * Stores all transactions. <br/>
 * Holds the following associated variables:
 * <ul>
 * <li>id(Long)</li>
 * <li>transactions(List&lt;Transaction&gt;)</li>
 * </ul>
 * <br>
 * <b>History:</b><br>
 *  - [13.06.2007] Created (Ulrich Staudinger)<br>
 *  - [14.07.2007] Added persistence + Arrays (Erik Nijkamp)<br>
 *  - [29.09.2007] Removed annotations (Erik Nijkamp)<br>
 *  - [28.02.2009] Added an add transaction method (Ulrich Staudinger)<br>
 *
 *  @author Ulrich Staudinger
 */
public class TransactionBook implements Serializable {

	private static final long serialVersionUID = 8193070780758673694L;
	/**
	 * private Long id;
	 */
	private Long id;
	/**
	 * private List&lt;Transaction&gt; transactions = new ArrayList&lt;Transaction&gt;();
	 */
	private List<Transaction> transactions = new ArrayList<Transaction>();	
	/**
	 * an empty TransactionBook constructor
	 */
	public TransactionBook() {

	}
	/**
	 * constructs a TransactionBook using the given transactions(Transaction...) to set its associated transactions(List&lt;Transaction&gt;)
	 * @param transactions
	 */
	public TransactionBook(Transaction... transactions) {
		setTransactions(transactions);
	}
	/**
	 * returns the associated id(Long)
	 * @return
	 */
	public Long getId() {
		return id;
	}
	/**
	 * sets the associated id(Long) with the given id(Long)
	 * @param id
	 */
	public void setId(Long id) {
		this.id = id;
	}
	/**
	 * returns whether the associated id(Long) is not <code>null</code>
	 * @return
	 */
	public boolean hasId() {
		return id != null;
	}
	/**
	 * returns the associated transactions(List&lt;Transaction&gt;) as a Transaction[] array
	 * @return
	 */
	public Transaction[] getTransactions() {
		return transactions.toArray(new Transaction[] {});
	}
	/**
	 * sets the associated transactions(List&lt;Transaction&gt;) with the given transactions(List&lt;Transaction&gt;)
	 * @param transactions
	 */
	public void setTransactions(List<Transaction> transactions) {
		this.transactions = transactions;
	}
	/**
	 * sets the associated transactions(List&lt;Transaction&gt;) with the given transactions(Transaction...)
	 * @param transactions
	 */
	public void setTransactions(Transaction... transactions) {
		this.transactions = ArrayUtils.asList(transactions);
	}
	/**
	 * adds the given aTransaction(Transaction) to the associated transactions(List&lt;Transaction&gt;)
	 * @param aTransaction
	 */
	public void addTransaction(Transaction aTransaction) {
		this.transactions.add(aTransaction);
	}
}
